package com.jsmtr.rms.controller;

import com.jsmtr.rms.entity.BaseUser;
import com.jsmtr.rms.entity.LayuiDataTableResultBean;
import com.jsmtr.rms.entity.ProjectInfo;
import com.jsmtr.rms.entity.ProjectInfoJobtemplate;
import com.jsmtr.rms.service.IProjectInfoJobTemplateService;
import com.jsmtr.rms.service.IUtilService;
import com.jsmtr.rms.utils.DateTools;
import com.jsmtr.rms.utils.EnumTools;
import com.jsmtr.rms.utils.ResultBean;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.xpath.objects.XObject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 岗位模板相关操作
 *
 * @author: cyx
 * @description:
 * @date: Created in 2018/9/3 17:20
 * @modified by:
 */
@Controller
@RequestMapping(value = "/ProjectJobTemplate")
public class ProjectJobTemplateController {

    @Resource
    private IProjectInfoJobTemplateService projectInfoJobTemplateService;

    @Resource
    private IUtilService utilService;

    private ResultBean resultBean = new ResultBean();

    @RequestMapping(value = "/index")
    public String index() {
        return "/ProjectJobTemplate/index";
    }

    @RequestMapping(value = "/queryByPage")
    public void queryByPage(HttpServletRequest request, HttpServletResponse response, ProjectInfoJobtemplate jobtemplate) {

        try {
            int perpage = Integer.parseInt(request.getParameter("perpage"));
            int page = Integer.parseInt(request.getParameter("page"));
            String type = jobtemplate.getType();
            String state = jobtemplate.getState();
            if (type != null && type.length() >= 1) {
                String ttype = type.trim();
                String stype = ttype.substring(ttype.length() - 1, ttype.length());
                jobtemplate.setType(stype);
            }
            if (state != null && state.length() >= 1) {
                String tstate = state.trim();
                state = tstate.substring(tstate.length() - 1, tstate.length());
                jobtemplate.setState(state);
            }
            Map<String, Object> map = projectInfoJobTemplateService.findProjectInfoJobTemplateByPage(page, perpage, jobtemplate);
            StringBuilder result = new StringBuilder();
            double pageCount = (Double) map.get("pageCount");
            double allcount = (Double) map.get("count");

            if (pageCount != 0) {
                Object object = map.get("list");
                int num = 1;
                for (ProjectInfoJobtemplate _jobtemplate : (List<ProjectInfoJobtemplate>) object) {
                    result.append("<tr><td><input type=\"checkbox\" id='cb_" + _jobtemplate.getId() + "' /></td>");
                    result.append("<td>" + (perpage * (page - 1) + num) + "</td>");
                    result.append("<td>" + _jobtemplate.getTempname() + "</td>");
                    result.append("<td>" + _jobtemplate.getJobname() + "</td>");
                    result.append("<td>" + _jobtemplate.getZpcount() + "</td>");
                    if (_jobtemplate.getType().equalsIgnoreCase("A")) {
                        result.append("<td>社招</td>");
                    } else if (_jobtemplate.getType().equalsIgnoreCase("B")) {
                        result.append("<td>校招</td>");
                    } else if (_jobtemplate.getType().equalsIgnoreCase("C")) {
                        result.append("<td>中专</td>");
                    } else if (_jobtemplate.getType().equalsIgnoreCase("D")) {
                        result.append("<td>内部</td>");
                    }
                    result.append("<td>" + _jobtemplate.getState() + "</td>");
                    result.append("<td>" + _jobtemplate.getWorkcont() + "</td>");
                    result.append("<td>" + _jobtemplate.getWorkreq() + "</td>");

                    result.append("<td><a onClick=enableTemp('" + _jobtemplate.getId() + "') style='color:#2b72dc;'>启用</a><a style='color:#2b72dc;' onClick=stopTemp('" + _jobtemplate.getId() + "')>停用</a></td></tr>");
                    num++;
                }
            } else {
                result.append("<tr style='display:none'><td></td></tr>");
            }
            result.append("<input type='hidden' id='pageCount' value='" + pageCount + "' />");
            result.append("<input type='hidden' id='allCount' value='" + allcount + "' />");
            utilService.printTextResult(result.toString(), response);
        } catch (Exception e) {
            e.printStackTrace();
            utilService.printTextResult("<tr><td colspan='9'>读取数据失败</td></tr><input type='hidden' id='pageCount' value='0' /><input type='hidden' id='allCount' value='0' />", response);
        }
    }

    @SuppressWarnings("unchecked")
    @ResponseBody
    @RequestMapping(value = "/queryByPageJson")
    public LayuiDataTableResultBean queryByPageJson(HttpServletRequest request, HttpServletResponse response, ProjectInfoJobtemplate jobtemplate) {
        LayuiDataTableResultBean result = new LayuiDataTableResultBean();
        try {
            int limit = Integer.parseInt(request.getParameter("limit"));
            int page = Integer.parseInt(request.getParameter("page"));
            String type = jobtemplate.getType();
            String state = jobtemplate.getState();
            if (type != null && type.length() >= 1) {
                String ttype = type.trim();
                String stype = ttype.substring(ttype.length() - 1, ttype.length());
                jobtemplate.setType(stype);
            }
            if (state != null && state.length() >= 1) {
                String tstate = state.trim();
                state = tstate.substring(tstate.length() - 1, tstate.length());
                jobtemplate.setState(state);
            }
            Map<String, Object> map = projectInfoJobTemplateService.findProjectInfoJobTemplateByPage(page, limit, jobtemplate);
            List<ProjectInfoJobtemplate> list = (List<ProjectInfoJobtemplate>) map.get("list");
            JSONArray data = new JSONArray();

            for (ProjectInfoJobtemplate template :
                    list) {
                JSONObject item = JSONObject.fromObject(template);
                item.put("typeS", getTypeS(template.getType()));
                data.add(item);
            }

            result.setCode(0);
            result.setMsg("success");
            result.setCount(((Double) map.get("count")).intValue());
            result.setData(data);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            result.setCount(-1);
            result.setMsg("err");
            return result;
        }
    }

    private String getTypeS(String type) {
        if (type.equalsIgnoreCase("A")) {
            return "社招";
        } else if (type.equalsIgnoreCase("B")) {
            return "校招";
        } else if (type.equalsIgnoreCase("C")) {
            return "中专";
        } else if (type.equalsIgnoreCase("D")) {
            return "内部";
        } else return "";
    }

    @RequestMapping(value = "/query")
    @ResponseBody
    public ResultBean query() {
        try {
            List<ProjectInfoJobtemplate> projectInfoJobtemplateList = projectInfoJobTemplateService.findAllProjectJobTemplate();
            resultBean.setState(true);
            resultBean.setMessage("操作成功!");
            resultBean.setUrl("no");
        } catch (Exception e) {
            e.printStackTrace();
            resultBean.setState(false);
            resultBean.setMessage("操作失败!");
            resultBean.setUrl("no");
        }
        return resultBean;
    }

  /*  @RequestMapping(value = "/findByName")
    @ResponseBody
    public ResultBean findByName(String jobName, String tempName, String state, String ptype) {
        try {
            if (ptype != null) {
                if (ptype.equalsIgnoreCase(String.valueOf(EnumTools.RecruitType.社会招聘.ordinal()))) {
                    ptype = "A";
                } else if (ptype.equalsIgnoreCase(String.valueOf(EnumTools.RecruitType.高校校园招聘.ordinal()))) {
                    ptype = "B";
                } else if (ptype.equalsIgnoreCase(String.valueOf(EnumTools.RecruitType.中专校园招聘.ordinal()))) {
                    ptype = "C";
                }
            }
            List<ProjectInfoJobtemplate> projectInfoJobtemplateList = projectInfoJobTemplateService.findProjectInfoJobTemplateByLike(state, jobName, tempName, ptype);
            if (projectInfoJobtemplateList != null && projectInfoJobtemplateList.size() > 0) {
                resultBean.setState(true);
                resultBean.setMessage("操作成功!");
                resultBean.setUrl("no");
                resultBean.setDatas(projectInfoJobtemplateList);
            } else {
                resultBean.setState(true);
                resultBean.setMessage("未查询到数据!");
                resultBean.setUrl("no");
                resultBean.setDatas(projectInfoJobtemplateList);
            }
        } catch (Exception e) {
            e.printStackTrace();
            resultBean.setState(false);
            resultBean.setMessage("操作失败!");
            resultBean.setUrl("no");
        }
        return resultBean;
    }*/

    @ResponseBody
    @RequestMapping(value = "/findByName", method = RequestMethod.GET)
    public LayuiDataTableResultBean LayuiDataTableResultBean(HttpServletRequest request, HttpServletResponse response,
                                               String jobName, String tempName, String state, String ptype) {
        try {
            int page = Integer.parseInt(request.getParameter("page"));
            int limit = Integer.parseInt(request.getParameter("limit"));

            if (ptype != null) {
                if (ptype.equalsIgnoreCase(String.valueOf(EnumTools.RecruitType.社会招聘.ordinal()))) {
                    ptype = "A";
                } else if (ptype.equalsIgnoreCase(String.valueOf(EnumTools.RecruitType.高校校园招聘.ordinal()))) {
                    ptype = "B";
                } else if (ptype.equalsIgnoreCase(String.valueOf(EnumTools.RecruitType.中专校园招聘.ordinal()))) {
                    ptype = "C";
                } else if (ptype.equalsIgnoreCase(String.valueOf(EnumTools.RecruitType.内部招聘.ordinal()))) {
                    ptype = "D";
                }else if (ptype.equalsIgnoreCase(String.valueOf(EnumTools.RecruitType.驾驶员招聘.ordinal()))) {
                    ptype = "E";
                }
            }
            List<ProjectInfoJobtemplate> projectInfoJobtemplateList = projectInfoJobTemplateService.findProjectInfoJobTemplateByLike(state, jobName, tempName, ptype);

            LayuiDataTableResultBean result = new LayuiDataTableResultBean();
            if (projectInfoJobtemplateList != null && projectInfoJobtemplateList.size() > 0) {
                JSONArray jsonArray = new JSONArray();
                int num = 1;
                int countALL = projectInfoJobtemplateList.size();
                int len = Math.min((countALL - limit * (page - 1)), limit);
                for(int j= 0;j<len;j++){
                    ProjectInfoJobtemplate pdata = projectInfoJobtemplateList.get(j+limit * (page - 1));
                    JSONObject jsonObject = new JSONObject();
                    jsonObject.put("id",  limit * (page - 1) + num);
                    jsonObject.put("jobdepart",pdata.getJobdepart());
                    jsonObject.put("jobname", pdata.getJobname());
                    jsonObject.put("count", pdata.getZpcount());
                    jsonObject.put("age", ((pdata.getAgef()==null)?"":pdata.getAgef())+((pdata.getAgef()!=null)&&(pdata.getAget()!=null)?"-":"")
                            +((pdata.getAget()==null)?"":pdata.getAget()));
                    jsonObject.put("educode", pdata.getEducode());
                    jsonObject.put("major", pdata.getMajor());
                    jsonObject.put("requirement", pdata.getWorkreq());
                    jsonObject.put("jobcontent", pdata.getWorkcont());
                    jsonObject.put("jobtype", pdata.getJobtype());
                    jsonObject.put("political", pdata.getPolitical());
                    jsonObject.put("educoderequ", pdata.getEduname());
                    jsonArray.add(jsonObject);
                    num++;
                }
                result.setCode(0);
                result.setMsg("success");
                result.setCount(projectInfoJobtemplateList.size());
                result.setData(jsonArray);
            } else {
                result.setCode(0);
                result.setMsg("未查询到数据");
            }
            return result;
        } catch (Exception e) {
            e.printStackTrace();

            LayuiDataTableResultBean result = new LayuiDataTableResultBean();
            result.setCount(-1);
            result.setMsg("err");
            return result;
        }
    }

    @ResponseBody
    @RequestMapping(value = "/findPlans", method = RequestMethod.GET)
    public LayuiDataTableResultBean findPlans(HttpServletRequest request, HttpServletResponse response) {
        try {
            int page = Integer.parseInt(request.getParameter("page"));
            int limit = Integer.parseInt(request.getParameter("limit"));

            //String pnameTemp = request.getParameter("key[pname]")  == null ?"":request.getParameter("key[pname]");

            // 切换到oa数据库，用完后必须再次手动切换会默认数据库，否则连接默认数据库失败
           /* DynamicDataSource.setCustomerType(DynamicDataSource.DATA_SOURCE_B);
           // List<ProjectInfoJobtemplate> departList2 = projectInfoJobTemplateService.findAllProjectJobTemplate();
            List<ArrayList> dcolumnsList = projectInfoJobTemplateService.findColumnsPlans("FORMMAIN_0598");
            List<ArrayList> departList = projectInfoJobTemplateService.findPlansALL_0598();
            // 切换默认数据库
            DynamicDataSource.setCustomerType(DynamicDataSource.DATA_SOURCE_A);
            Integer position_0598_ID = 0;
            Integer position_0598_depart = 0;
            Integer countALL = 0;
            Object[][] arrayTemp1 = new Object[dcolumnsList.size()][];
            Integer a = 0;
            for(int m=0;m<dcolumnsList.size();m++){
                arrayTemp1[m] = (Object[]) dcolumnsList.toArray()[m];//每行的列数
                if("ID".equals(arrayTemp1[m][1])){
                    position_0598_ID = m;
                    a++;
                    if(a > 1) {
                        break;
                    }
                } else if("FIELD0001".equals(arrayTemp1[m][1])){
                    position_0598_depart = m;
                    a++;
                    if(a > 1)
                        break;
                }
            }

            JSONArray jsonArray = new JSONArray();
            if(departList.size() > 0){
                String[] ids =new String[departList.size()];
                String[] departs =new String[departList.size()];
                Object[][] arrayTemp2 = new Object[departList.size()][];
                for(int i=0;i<departList.size();i++){
                    arrayTemp2[i] = (Object[]) departList.toArray()[i];//每行的列数
                    ids[i] = (String) arrayTemp2[i][position_0598_ID];
                    departs[i] = (String) arrayTemp2[i][position_0598_depart];
                }

                // 切换到oa数据库，用完后必须再次手动切换会默认数据库，否则连接默认数据库失败
                DynamicDataSource.setCustomerType(DynamicDataSource.DATA_SOURCE_B);
                List<ArrayList> jcolumnsList = projectInfoJobTemplateService.findColumnsPlans("FORMMAIN_0599");
                List<ArrayList> jobsList = projectInfoJobTemplateService.findPlans_0599(ids);
                // 切换默认数据库
                DynamicDataSource.setCustomerType(DynamicDataSource.DATA_SOURCE_A);
                Integer position_0599_data[] = new Integer[jcolumnsList.size()];
                Object[][] arrayTemp3 = new Object[jcolumnsList.size()][];
                for(int z=0;z<jcolumnsList.size();z++){
                    arrayTemp3[z] = (Object[]) jcolumnsList.toArray()[z];//每行的列数
                    if ("ID".equals(arrayTemp3[z][1])) {
                        position_0599_data[0] = z;
                    } else if ("FORMMAIN_ID".equals(arrayTemp3[z][1])) {
                        position_0599_data[1] = z;
                    } else if ("FIELD0002".equals(arrayTemp3[z][1])) {
                        position_0599_data[2] = z;
                    } else if ("FIELD0006".equals(arrayTemp3[z][1])) {
                        position_0599_data[3] = z;
                    } else if ("FIELD0010".equals(arrayTemp3[z][1])) {
                        position_0599_data[4] = z;
                    } else if ("FIELD0012".equals(arrayTemp3[z][1])) {
                        position_0599_data[5] = z;
                    } else if ("FIELD0014".equals(arrayTemp3[z][1])) {
                        position_0599_data[6] = z;
                    } else if ("FIELD0016".equals(arrayTemp3[z][1])) {
                        position_0599_data[7] = z;
                    } else if ("FIELD0018".equals(arrayTemp3[z][1])) {
                        position_0599_data[8] = z;
                    } else if ("FIELD0025".equals(arrayTemp3[z][1])) {
                        position_0599_data[9] = z;
                    } else if ("FIELD0027".equals(arrayTemp3[z][1])) {
                        position_0599_data[10] = z;
                    } else if ("FIELD0028".equals(arrayTemp3[z][1])) {
                        position_0599_data[11] = z;
                    } else if ("FIELD0029".equals(arrayTemp3[z][1])) {
                        position_0599_data[12] = z;
                    } else if ("FIELD0030".equals(arrayTemp3[z][1])) {
                        position_0599_data[13] = z;
                    }
                }

                if(jobsList.size()>0){
                    countALL = Integer.valueOf(jobsList.size());
                    int num = 1;
                    Object[][] arrayTemp4 = new Object[jobsList.size()][];
                    Integer len = (countALL<limit)?countALL:limit;
                    for(int j= limit * (page - 1);j<len;j++){
                        arrayTemp4[j] = (Object[]) jobsList.toArray()[j];//每行的列数
                        JSONObject jsonObject = new JSONObject();
                        jsonObject.put("id",  limit * (page - 1) + num);
                        for(int n=0;n<ids.length;n++){
                            if(ids[n].equals(arrayTemp4[j][position_0599_data[1]])){
                                jsonObject.put("jobdepart", departs[n]);
                                break;
                            }
                        }
                        jsonObject.put("jobname", arrayTemp4[j][position_0599_data[2]]);
                        jsonObject.put("count", arrayTemp4[j][position_0599_data[3]]);
                        jsonObject.put("age", arrayTemp4[j][position_0599_data[4]]);
                        jsonObject.put("educode", arrayTemp4[j][position_0599_data[5]]);
                        jsonObject.put("major", arrayTemp4[j][position_0599_data[6]]);
                        jsonObject.put("requirement", arrayTemp4[j][position_0599_data[7]]);
                        jsonObject.put("jobcontent", arrayTemp4[j][position_0599_data[8]]);
                        jsonObject.put("type", arrayTemp4[j][position_0599_data[9]]);
                        jsonObject.put("political", arrayTemp4[j][position_0599_data[10]]);
                        jsonObject.put("jobtitles", arrayTemp4[j][position_0599_data[11]]);
                        jsonObject.put("educoderequ", arrayTemp4[j][position_0599_data[12]]);
                        jsonObject.put("bz", arrayTemp4[j][position_0599_data[13]]);

                        jsonArray.add(jsonObject);
                        num++;
                    }
                }
            }*/

            LayuiDataTableResultBean result = new LayuiDataTableResultBean();
            result.setCode(0);
            result.setMsg("success");
           // result.setCount(countALL);
          //  result.setData(jsonArray);

            return result;

        } catch (Exception e) {
            e.printStackTrace();

            LayuiDataTableResultBean result = new LayuiDataTableResultBean();
            result.setCount(-1);
            result.setMsg("err");
            return result;
        }
    }

    @RequestMapping(value = "/getJobTemplate")
    @ResponseBody
    public ResultBean getJobTemplate(@RequestParam(required = true) String tempid) {

        try {
            ProjectInfoJobtemplate jobtemplate = projectInfoJobTemplateService.getPorjectJobTemplate(tempid);
            resultBean.setState(true);
            resultBean.setMessage("操作成功!");
            resultBean.setUrl("no");
            resultBean.setDatas(jobtemplate);
        } catch (Exception e) {
            resultBean.setState(false);
            resultBean.setMessage("操作失败!");
            resultBean.setUrl("no");
        }
        return resultBean;
    }


    @RequestMapping(value = "/add")
    @ResponseBody
    public ResultBean add(ProjectInfoJobtemplate jobtemplate, HttpServletRequest request) {

        try {
            if (jobtemplate.getId() == null && jobtemplate.getId().trim().length() < 0) {
                jobtemplate.setId(UUID.randomUUID().toString());
                BaseUser usr = utilService.getSessionUser(request);
                jobtemplate.setCreateuser(usr.getUname());
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                jobtemplate.setCreatetime(simpleDateFormat.format(new Date()));
                projectInfoJobTemplateService.addProjectJobTemplate(jobtemplate);
            }
            resultBean.setState(true);
            resultBean.setMessage("操作成功!");
            resultBean.setUrl("no");
            resultBean.setDatas(jobtemplate);
        } catch (Exception e) {
            e.printStackTrace();
            resultBean.setState(false);
            resultBean.setMessage("操作失败!");
            resultBean.setUrl("no");
        }
        return resultBean;
    }

    @RequestMapping(value = "/edit")
    public String edit(HttpServletRequest request, Model model) {
        String id = request.getParameter("id");
        if (id != null && id.trim().length() > 0) {
            try {
                ProjectInfoJobtemplate jobtemplate = projectInfoJobTemplateService.getPorjectJobTemplate(id);
                model.addAttribute("jobtemplate", jobtemplate);
            } catch (Exception e) {
                // e.printStackTrace();
            }


        }
        return "/ProjectJobTemplate/edit";
    }

    @RequestMapping(value = "/saveOrUpdate")
    @ResponseBody
    public ResultBean saveOrUpdate(ProjectInfoJobtemplate jobtemplate, HttpServletRequest request) {
        try {
            if (jobtemplate.getId() != null && jobtemplate.getId().trim().length() > 0) {
                BaseUser usr = utilService.getSessionUser(request);
                String tempid = request.getParameter("tempid");
                if (tempid != null && tempid.length() > 0) {
                    jobtemplate.setId(tempid);
                }
                jobtemplate.setEdituser(usr.getUname());
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                jobtemplate.setEdittime(simpleDateFormat.format(new Date()));
                if (jobtemplate.getJobdepart() == null) {
                    jobtemplate.setJobdepart("");
                }
                projectInfoJobTemplateService.editProjectJobTemplate(jobtemplate);
            } else {
                jobtemplate.setId(UUID.randomUUID().toString());

                jobtemplate.setState("启用");

                if (jobtemplate.getTempname() != null && jobtemplate.getTempname().length() > 0) {
                    List<ProjectInfoJobtemplate> projectInfoJobtemplateList = projectInfoJobTemplateService.findProjectInfoJobTemplateByLike(jobtemplate.getState(), null, jobtemplate.getTempname(), jobtemplate.getType());
                    if (projectInfoJobtemplateList != null && projectInfoJobtemplateList.size() > 0) {
                        resultBean.setState(false);
                        resultBean.setMessage("操作失败!,<br/>已存在名为<span color='red'>" + jobtemplate.getTempname() + "</span>的模板!");
                        resultBean.setUrl("no");
                        return resultBean;
                    }
                } else {
                    List<ProjectInfoJobtemplate> projectInfoJobtemplateList = projectInfoJobTemplateService.findProjectInfoJobTemplateByLike(jobtemplate.getState(), jobtemplate.getJobname(), null, jobtemplate.getType());
                    String ptype = request.getParameter("ptype");
                    jobtemplate.setType(ptype);
                    if (projectInfoJobtemplateList != null && projectInfoJobtemplateList.size() > 0) {
                        SimpleDateFormat dateFormat = new SimpleDateFormat("yyMMdd");
                        jobtemplate.setTempname(jobtemplate.getJobname() + "[" + dateFormat.format(new Date()) + (projectInfoJobtemplateList.size() + 1) + "]");
                    } else {
                        jobtemplate.setTempname(jobtemplate.getJobname());
                    }
                }
                BaseUser usr = utilService.getSessionUser(request);
                jobtemplate.setCreateuser(usr.getUname());
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

                jobtemplate.setCreatetime(simpleDateFormat.format(new Date()));
                if (jobtemplate.getJobdepart() == null) {
                    jobtemplate.setJobdepart("");
                }
                projectInfoJobTemplateService.addProjectJobTemplate(jobtemplate);

            }
            resultBean.setState(true);
            resultBean.setMessage("操作成功!");
            resultBean.setUrl("no");
            resultBean.setDatas(jobtemplate);
        } catch (Exception e) {
            e.printStackTrace();
            resultBean.setState(false);
            resultBean.setMessage("操作失败!");
            resultBean.setUrl("no");
        }
        return resultBean;
    }

    @RequestMapping(value = "/delete")
    @ResponseBody
    public ResultBean delete(ProjectInfoJobtemplate jobtemplate, @RequestParam(value = "id", required = true) String ids ) {
        String[] idArr = ids.split(",");
        try {
            if (idArr.length > 0) {
                for (int i = 0; i < idArr.length; i++) {
                    jobtemplate = projectInfoJobTemplateService.getPorjectJobTemplate(idArr[i]);
                    if (jobtemplate.getJobdepart() == null) {
                        jobtemplate.setJobdepart("");
                    }
                    projectInfoJobTemplateService.deleteProjectJobTemplate(jobtemplate);
                }
                resultBean.setState(true);
                resultBean.setMessage("操作成功!");
                resultBean.setUrl("no");
                resultBean.setDatas(jobtemplate);
            }

        } catch (Exception e) {
            e.printStackTrace();
            resultBean.setState(false);
            resultBean.setMessage("操作失败!");
            resultBean.setUrl("no");
        }
        return resultBean;
    }

    @RequestMapping(value = "/stop")
    @ResponseBody
    public ResultBean stop(ProjectInfoJobtemplate jobtemplate, @RequestParam(value = "id", required = true) String ids) {
        String[] idArr = ids.split(",");
        try {
            if (idArr.length > 0) {
                for (int i =0; i < idArr.length; i++) {
                    jobtemplate = projectInfoJobTemplateService.getPorjectJobTemplate(idArr[i]);
                    jobtemplate.setState("停用");
                    if (jobtemplate.getJobdepart() == null) {
                        jobtemplate.setJobdepart("");
                    }
                    projectInfoJobTemplateService.editProjectJobTemplate(jobtemplate);
                }
                resultBean.setState(true);
                resultBean.setMessage("操作成功!");
                resultBean.setUrl("no");
                resultBean.setDatas(jobtemplate);
            }

        } catch (Exception e) {
            e.printStackTrace();
            resultBean.setState(false);
            resultBean.setMessage("操作失败!");
            resultBean.setUrl("no");
        }
        return resultBean;
    }

    @RequestMapping(value = "/start")
    @ResponseBody
    public ResultBean start(ProjectInfoJobtemplate jobtemplate, @RequestParam(value = "id", required = true) String ids) {
        String[] idArr = ids.split(",");
        try {
            if (idArr.length > 0) {
                for (int i = 0; i < idArr.length; i++) {
                    jobtemplate = projectInfoJobTemplateService.getPorjectJobTemplate(idArr[i]);
                    jobtemplate.setState("启用");
                    if (jobtemplate.getJobdepart() == null) {
                        jobtemplate.setJobdepart("");
                    }
                    projectInfoJobTemplateService.editProjectJobTemplate(jobtemplate);
                }
                resultBean.setState(true);
                resultBean.setMessage("操作成功!");
                resultBean.setUrl("no");
                resultBean.setDatas(jobtemplate);
            }

        } catch (Exception e) {
            e.printStackTrace();
            resultBean.setState(false);
            resultBean.setMessage("操作失败!");
            resultBean.setUrl("no");
        }
        return resultBean;
    }
}
